package com.app.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.IntSummaryStatistics;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.stream.Collectors;

import com.app.controller.base.BaseController;
import com.app.interceptor.ExceptionInterceptor;
import com.app.service.LogService;
import com.jfinal.aop.Before;
import com.jfinal.kit.HttpKit;
import com.web.annotation.UrlMapper;

@UrlMapper(val="/logger")
public class LogController extends BaseController {
	private LogService logService = new LogService();
	
	@Before(ExceptionInterceptor.class)
	public Map<String, Object> logTest() throws Exception {
		System.out.println("###"+getParaMap());
		System.out.println("json"+HttpKit.readData(getRequest()));
		return logService.logTest();
	}
	
	@Before(ExceptionInterceptor.class)
	public Map<String, Object> logTest2() throws Exception {
		System.out.println("###"+getParaMap());
		System.out.println("json"+HttpKit.readData(getRequest()));
		return logService.logTest();
	}
	
	public void logNull() throws Exception {
		renderJson(logService.logTest());
		return;
	}
	


	public static void main(String[] args) {
		/*List<String> myList = Arrays.asList("a1", "a2", "b1", "c2", "c1");
		myList
		    .stream() // 创建流
		    .filter(s -> s.startsWith("c")) // 执行过滤，过滤出以 c 为前缀的字符串
		    .map(String::toUpperCase) // 转换成大写
		    .sorted() // 排序
		    .forEach(System.out::println); // for 循环打印
		
		List<String> strings = Arrays.asList("abc", "", "bc", "efg", "abcd","", "jkl");
	    System.out.println("列表: " +strings);

	    long count = strings.stream().filter(string->string.isEmpty()).count();
	    System.out.println("空字符串数量为: " + count);

	    count = strings.stream().filter(string -> string.length() == 3).count();
	    System.out.println("字符串长度为 3 的数量为: " + count);

	    List<String> filtered = strings.stream().filter(string ->!string.isEmpty()).collect(Collectors.toList());
	    System.out.println("筛选后的列表: " + filtered);

	    String mergedString = strings.stream().filter(string ->!string.isEmpty()).collect(Collectors.joining(", "));
	    System.out.println("合并字符串: " + mergedString);

	    List<Integer> numbers = Arrays.asList(3, 2, 2, 3, 7, 3, 5);
	    List<Integer> squaresList = numbers.stream().map( i ->i*i).distinct().collect(Collectors.toList());
	    System.out.println("去重: " + squaresList);

	    List<Integer> integers = Arrays.asList(1,2,13,4,15,6,17,8,19);
	    System.out.println("列表: " +integers);
	    IntSummaryStatistics stats = integers.stream().mapToInt((x) ->x).summaryStatistics();

	    System.out.println("列表中最大的数 : " + stats.getMax());
	    System.out.println("列表中最小的数 : " + stats.getMin());
	    System.out.println("所有数之和 : " + stats.getSum());
	    System.out.println("平均数 : " + stats.getAverage());

	    // 并行处理
	    count = strings.parallelStream().filter(string -> string.isEmpty()).count();
	    System.out.println("空字符串的数量为: " + count);*/

	    /*System.out.println("随机数: ");
	    Random random = new Random();
	    random.ints().limit(10).sorted().forEach(System.out::println);*/
	    
	    List<String> list = new ArrayList<String>();
        //list.add("王华安");
        //list.add("孙志强");
        list.add("赵一鹏");
        //list.add("沈丽丽");
        //list.add("张虎成");
        list.add("王海峰");
        list.add("李壮");
        list.add("赵超");
        //list.add("梁鹏");
        //list.add("高婷茹");
        //list.add("李妍");
        list.add("孙旭东");
        list.add("朱立凯");
        //list.add("黄珊珊");
        //list.add("杨天");
        list.add("刘平");

        Collections.shuffle(list);
        list.stream()
        	.limit(6)
        	.forEach(System.out::println);
        
        
	}
}
